<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>京东某个商品价格信息</title>
		<script src="js/jquery.min.js"></script>
	</head>
	<body>
		<div>
			商品编号:<span id="id"></span>
		</div>
		<div>
			商品价格:<span id="price"></span>
		</div>
	</body>
	<script>
		//1.实现写死的json字符串,解析展现到页面上
		var jsonstr = '[{"p":"17888.00","op":"17888.00","cbf":"0","id":"J_100013651682","m":"27999.00"}]';
		//2.获取价格和编号
		var obj = JSON.parse(jsonstr); //把字符串转换成js对象file:///G:/课程/前端/sc/res/js/vue.js
		
		//发起ajax请求
		$.ajax({
			type:"get",
			url:"https://p.3.cn/prices/mgets?skuIds=J_100013651682",
			dataType:"jsonp",
			success:function(data){
				console.log(data);
				var obj=data; //把data赋值给obj
				
				var price = obj[0].p; //获取到数组第一条记录,访问p属性
				var id=obj[0].id;
		
				console.log(price);
				console.log(id);
		
				//3.将内容写道页面,进行展示
				$("#id").text(id); //span属性标签写法
				$("#id").css("color","blue"); //渲染
				$("#price").text(price).css("color","red");
			}
		})
		
		
	</script>
</html>
